package com.atguigu.gulimall.search.config;

import io.netty.util.concurrent.DefaultThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;

@Configuration
@EnableAsync
public class EsThreadPool {


    @Bean("executor")
    public Executor getExecutor() {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5,    //核心线程数
                200,    //最大线程数量，控制资源并发
                10,    //存活时间
                TimeUnit.SECONDS,    //时间单位
                new LinkedBlockingDeque<>(1000),
                new DefaultThreadFactory("es"),
                new ThreadPoolExecutor.AbortPolicy()
        );
        return executor;
    }
}
